class Solution
{
public:
    int maximumTop(vector<int> &nums, int k)
    {
        int n = nums.size();
        if (n == 1 && (k & 1))
        {
            return -1;
        }
        int maxNum = 0;
        int upper = min(k - 1, n);
        for (int i = 0; i < upper; ++i)
        {
            maxNum = max(maxNum, nums[i]);
        }
        if (k < n)
        {
            maxNum = max(maxNum, nums[k]);
        }
        return maxNum;
    }
};